package com.yjhb.android.sbz.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.yjhb.android.sbz.App;
import com.yjhb.android.sbz.R;
import com.yjhb.android.sbz.entity.RedPackItem;
import com.jojo.android.zxlib.base.BaseRecyclerAdapter;
import com.jojo.android.zxlib.tool.ZxTimeTool;
import com.jojo.android.zxlib.view.CircleImageView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 创建者 zx
 * 创建时间 2021/1/14 17:28
 */
public class RedPackDetailAdapter extends BaseRecyclerAdapter<RedPackDetailAdapter.Holder, RedPackItem> {
    private final String TAG = "RedPackDetailAdapter";

    public RedPackDetailAdapter(Context context) {
        super(context);
    }

    @Override
    protected Holder getHolder(View v) {
        return new Holder(v);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.item_red_pack_detail;
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int position) {
        Glide.with(context).load(entity.getAvatar()).into(holder.headIv);
        holder.nameTv.setText(entity.getNickName());
        holder.timeTv.setText(ZxTimeTool.getDate(entity.getCreateTime().getTime(), "yyyy-MM-dd HH:mm:ss:SSS"));
        holder.moneyTv.setText(entity.getMoney().setScale(2).toString() + "元");
        if (entity.getUserId() == Integer.parseInt(App.userInfo.getId())) {
            holder.nameTv.setTextColor(Color.RED);
            holder.moneyTv.setTextColor(Color.RED);
            holder.timeTv.setTextColor(Color.RED);
        } else {
            holder.nameTv.setTextColor(Color.BLACK);
            holder.moneyTv.setTextColor(Color.BLACK);
            holder.timeTv.setTextColor(Color.BLACK);
        }
    }

    class Holder extends RecyclerView.ViewHolder {
        @BindView(R.id.head_iv)
        CircleImageView headIv;
        @BindView(R.id.name_tv)
        TextView nameTv;
        @BindView(R.id.time_tv)
        TextView timeTv;
        @BindView(R.id.money_tv)
        TextView moneyTv;

        public Holder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
